package com.ruoyi.heima.news.factory;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.heima.news.client.NewsClient;
import com.ruoyi.heima.news.domain.News;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class NewsFallbackFactory implements FallbackFactory<NewsClient> {
    @Override
    public NewsClient create(Throwable cause) {
        return new NewsClient() {
            @Override
            public AjaxResult addNewsFromNotice(News news) {
                return AjaxResult.error("同步系统新增通知公告失败！",cause.getMessage());
            }

            @Override
            public AjaxResult updateNewsByNoticeId(News news) {
                return AjaxResult.error("同步系统更新通知公告失败！",cause.getMessage());
            }

            @Override
            public News selectNewsByNoticeId(Long noticeId) {
                return null;
            }

            @Override
            public Boolean deleteNewsFromNotice(Long[] noticeIds) {
                return AjaxResult.error("同步系统更新通知公告失败！" + cause.getMessage()).isError();
            }

            @Override
            public AjaxResult deletedOneWeekAgoNews() {
                return AjaxResult.error("删除一周前的新闻失败！",cause.getMessage());
            }
        };
    }
}
